<style type="text/css">
    #customBtn {
      display: inline-block;
      background: url('<?php echo STATIC_URL ?>/img/google-signin-bg.png');
	  background-position:right;
	  background-repeat:no-repeat;
      color: white;
      width: 162px;
      height: 29px;
    }
    #customBtn:hover {
      cursor: hand;
    }
    span.icon {
      background: url('<?php echo STATIC_URL ?>/img/google-signin-icon.png') transparent 5px 50% no-repeat;
      display: inline-block;
      width: 29px;
      height: 29px;
    }
  </style>
<div class="main-wrap">
	<section id="list-view-2" class="badge-list-view-element variant-right">
	<script>
	function signinCallback(authResult) {
	  if (authResult['access_token']) {
		// Update the app to reflect a signed in user
		$('#info-msg').html('Login successful. Fetching your information...');
		$('#info-msg').show();
		$.ajax({
		  url: BASE_URL + '/user/gplusauth',
		  type: 'POST',
		  data: {token: authResult['access_token']},
		  success: function(response){
			if(response === '1'){
				location.href = BASE_URL;
			}
			else{
				$('#error-msg').html('Error when getting data, please try again later.');
				$('#error-msg').show();
			}
		  }
		});
		//document.getElementById('signinButton').setAttribute('style', 'display: none');
		//$('#btnGplusLogout').show();
	  } else if (authResult['error']) {
		// Update the app to reflect a signed out user
		// Possible error values:
		//   "user_signed_out" - User is signed-out
		//   "access_denied" - User denied access to your app
		//   "immediate_failed" - Could not automatically log in the user
		//console.log('Sign-in state: ' + authResult['error']);
	  }
	}
	function gplusLogout(){
	  gapi.auth.signOut();
	  //document.location.href = '?act=logout';
	}
	function fbLogin(){
		 FB.login(function(response) {
		   if (typeof response.authResponse.accessToken != 'undefined') {
				$('#info-msg').html('Login successful. Fetching your information...');
				$('#info-msg').show();
				$.ajax({
					url: BASE_URL + '/user/fbauth',
					type: 'POST',
					data: {token: response.authResponse.accessToken},
					success: function(response){
						//console.log(response);
					  if(response === '1'){
						location.href = BASE_URL;
					  }
					  else{
						$('#error-msg').html('Error when getting data, please try again later.');
						$('#error-msg').show();
					  }
					}
				});
		   } else {
			 //console.log('User cancelled login or did not fully authorize.');
		   }
		}, {scope: 'email', response_type: 'code'});
	}
	</script>
	<a onClick="fbLogin()" href="javascript:void(0)"><img src="<?php echo STATIC_URL ?>/img/fb-signin.png" /></a>
	<div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>
      <span class="buttonText"></span>
    </div>

	<div class="error-msg" id="error-msg" style="display:none"></div>
	<div class="info-msg" id="info-msg" style="display:none"></div>
	</section>
</div>
<script type="text/javascript">
  (function() {
   var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
   po.src = 'https://apis.google.com/js/client:plusone.js?onload=gplusCallback';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
 })();
</script>
<script>
function gplusCallback(){
	gapi.signin.render('customBtn', {
	  'callback': 'signinCallback',
	  'clientid': '992072006437-s7vu3g4vdlb7sb2q3gl9b9vd9avo3ioh.apps.googleusercontent.com',
	  'cookiepolicy': 'single_host_origin',
	  'requestvisibleactions': 'http://schemas.google.com/AddActivity',
	  'scope': 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
	});
}
</script>